import 'package:flutter/material.dart';
import 'package:flutter_test_demo/pages/home/components/TabInfoGrid.dart';
import 'package:flutter_test_demo/static/colors/MyColors.dart';

class DiscoverPage extends StatelessWidget {
  const DiscoverPage({Key key}) : super(key: key);


  
  @override
  Widget build(BuildContext context) {
    final List<TabInfo> _tabs = [
      TabInfo("美食", TabInfoGrid(titleName: "美食")),
      TabInfo("古镇", TabInfoGrid(titleName: "古镇")),
      TabInfo("景点", TabInfoGrid(titleName: "景点")),
      TabInfo("打卡", TabInfoGrid(titleName: "打卡"))
    ];


    return DefaultTabController(
      length: _tabs.length,
      child: Scaffold(
        appBar: AppBar(
          title: Text("发现"),
          backgroundColor: MyColor.titleColor,
          centerTitle: true,
          bottom: PreferredSize(
            
            child: TabBar(
              isScrollable: false,
              tabs: _tabs.map((e) => 
                Tab(text: e.label)
              ).toList()
            ), 
            preferredSize: Size.fromHeight(30.0)
          ),
        ),
        body: Container(
          width: double.infinity,
          height: double.infinity,
          child: TabBarView(
            children: _tabs.map((e) => 
              e.widget
            ).toList()
          ),
        ),
      ),
    );
  }
}


class TabInfo {
  String label;
  Widget widget;
  TabInfo(this.label,this.widget);
}